<template>
  <div id="change">
    <div class="change-top">
      单据日期：
      <el-date-picker size="small" v-model="value1" style="width: 140px;" placeholder="选择日期">
      </el-date-picker>
      &nbsp;&nbsp;组装费用：
      <el-input size="small" style="width: 120px" placeholder="0.00"></el-input>
      &nbsp;&nbsp;业务员：
      <el-select style="width: 110px;" size="small">
      </el-select>
      <!-- &nbsp;&nbsp;部门：
      <el-select style="width: 110px;" size="small">

      </el-select> -->
      &nbsp;&nbsp;
      <el-button size="small">保存</el-button>
      <el-button size="small" type="primary">导入</el-button>
      <el-button size="small" type="success">审核</el-button>
      <PublicLink />
    </div>
    <div class="change-content">
      <!-- <hr>
      <br>
      <el-button>选择模版</el-button>
      <el-button>存为模版</el-button>
      <br>
      <br> -->
      <h5>组合件：</h5>
      <!-- <span style="margin-right: 70px;">模版编号：</span><span>模版名称：</span> -->
      <br>
      <br>
      <el-table :row-style="{ height: '40px' }" @row-click="handlerClick" height="130px" :data="comboBill" border
        style="width: 100%;font-size: 13px;">
        <el-table-column prop="createDate" label="商品编号" width="150">
          <template slot-scope="scope">
            <el-input size="small" v-if="scope.row.isEdit"></el-input>
            <span v-else>{{ scope.row.createDate }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="code" label="商品类别" width="120">
        </el-table-column>
        <el-table-column prop="pid" label="品牌" width="120">
        </el-table-column>
        <el-table-column prop="mid" label="属性" width="150">
        </el-table-column>
        <el-table-column prop="aid" label="单位" width="120">
        </el-table-column>
        <el-table-column prop="aid" label="仓库" width="120">
          <template slot-scope="scope">
            <el-select size="small" v-if="scope.row.isEdit"></el-select>
          </template>
        </el-table-column>
        <el-table-column prop="aid" label="可用库存" width="120">
        </el-table-column>
        <el-table-column prop="aid" label="数量" width="120">
          <template slot-scope="scope">
            <el-input size="small" v-if="scope.row.isEdit"></el-input>
            <span v-else>{{ scope.row.aid }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="aid" label="入库单位成本" width="120">
        </el-table-column>
        <el-table-column prop="aid" label="入库成本" width="120">
        </el-table-column>
        <el-table-column prop="remark" label="备注" width="180">
          <template slot-scope="scope">
            <el-input size="small" v-if="scope.row.isEdit"></el-input>
            <span v-else>{{ scope.row.remark }}</span>
          </template>
        </el-table-column>
      </el-table>
      <br>
      <h5>子件：</h5>
      <br>
      <el-table @row-click="handlerClick2" show-summary :summary-method="getSummaries" height="300px" :data="tableData"
        border style="width: 100%;font-size: 13px;">
        <el-table-column prop="createDate" label="商品编号" width="150">
          <template slot-scope="scope">
            <el-input size="small" v-if="scope.row.isEdit"></el-input>
            <span v-else>{{ scope.row.createDate }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="pid" label="品牌" width="120">
        </el-table-column>
        <el-table-column prop="mid" label="属性" width="150">
        </el-table-column>
        <el-table-column prop="aid" label="单位" width="120">
        </el-table-column>
        <el-table-column prop="aid" label="仓库" width="120">
          <template slot-scope="scope">
            <el-select size="small" v-if="scope.row.isEdit"></el-select>
          </template>
        </el-table-column>
        <el-table-column prop="aid" label="可用库存" width="120">
        </el-table-column>
        <el-table-column prop="aid" label="数量" width="120">
          <template slot-scope="scope">
            <el-input size="small" v-if="scope.row.isEdit"></el-input>
            <span v-else>{{ scope.row.aid }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="aid" label="出库单位成本" width="120">
        </el-table-column>
        <el-table-column prop="aid" label="出库成本" width="120">
        </el-table-column>
        <el-table-column prop="remark" label="备注" width="180">
          <template slot-scope="scope">
            <el-input size="small" v-if="scope.row.isEdit"></el-input>
            <span v-else>{{ scope.row.remark }}</span>
          </template>
        </el-table-column>
      </el-table>
      <el-button style="position: relative;right: -1200px;" @click="goto('ComboBill')">历史单据</el-button>
    </div>

  </div>
</template>

<script>
import PublicLink from '../public_com/PublicLink.vue';


export default {
  name: 'AddComboBill',
  components: {
    PublicLink
  },
  data() {
    return {//分页参数
      currentPage1: 5,
      currentPage2: 5,
      currentPage3: 5,
      currentPage4: 4,
      //新增对话框
      dialogFormVisible: false,
      switchValue: '1',
      options: [{
        value: '选项1',
        label: '黄金糕'
      }, {
        value: '选项2',
        label: '双皮奶'
      }, {
        value: '选项3',
        label: '蚵仔煎'
      }, {
        value: '选项4',
        label: '龙须面'
      }, {
        value: '选项5',
        label: '北京烤鸭'
      }],
      value: '',
      input: '',
      comboBill: [
        {
          goodsId: '',
          code: "",
          unit: '',
          pid: '',
          mid: '',
          aid: '',
          num: '',
          outWid: '',
          inputWid: '',
          aboutCode: '',
          remark: '',
          createDate: '',
          status: '',
          state: '',
          isEdit: false
        },
      ],
      tableData: [{
        goodsId: '11111',
        code: "12121212",
        unit: '瓶',
        pid: '11',
        mid: '22',
        aid: '33',
        num: 100,
        outWid: '1121',
        inputWid: '121',
        aboutCode: '232323',
        remark: '',
        createDate: '2024-12-16',
        status: '1',
        state: '1212',
        isEdit: false
      },
      {
        goodsId: '11111',
        code: "12121212",
        unit: '瓶',
        pid: '11',
        mid: '22',
        aid: '33',
        num: 100,
        outWid: '1121',
        inputWid: '121',
        aboutCode: '232323',
        remark: '',
        createDate: '2024-12-16',
        status: '1',
        state: '1212',
        isEdit: false
      },
      {
        goodsId: '11111',
        code: "12121212",
        unit: '瓶',
        pid: '11',
        mid: '22',
        aid: '33',
        num: 100,
        outWid: '1121',
        inputWid: '121',
        aboutCode: '232323',
        remark: '',
        createDate: '2024-12-16',
        status: '1',
        state: '1212',
        isEdit: false
      },
      ],
      value1: '',
    }
  },
  methods: {
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
    goto(to) {
      this.$router.push(to)
    },
    handlerClick(row, column, event) {
      this.comboBill.forEach((store, index) => {
        store.isEdit = false
      })
      row.isEdit = true
    },
    handlerClick2(row, column, event) {
      this.tableData.forEach((store, index) => {
        store.isEdit = false
      })
      row.isEdit = true
    },
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '总价';
          return;
        }
        const values = data.map(item => Number(item[column.property]));
        if (column.property === "num") {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
        }
      });

      return sums;
    }

  }

}
</script>

<style scoped>
#change {
  width: 100%;
  height: 100%;
}

.change-top {
  width: calc(100% -20px);
  height: 60px;
  /* background-color: pink; */
  line-height: 60px;
  padding-left: 20px;
  font-size: 13px;
}

.change-content {
  width: 100%;
  height: calc(100% - 60px);
  /* background-color: skyblue; */
}

.el-input,
.el-button {
  font-size: 13px;
}

/* 合计行整体样式修改开始 */
.el-table /deep/ .el-table__footer-wrapper tbody td {
  background-color: #fff1d4;
}

.el-table /deep/ .el-table__body tr:hover>td {
  background-color: #fff1d4;
}
</style>